<?php

namespace app\home\controller;

use think\Db;
use app\home\model\Game as GameModel;

// 二维码生成调用类
use Endroid\QrCode\ErrorCorrectionLevel;
use Endroid\QrCode\LabelAlignment;
use Endroid\QrCode\QrCode;

class Game extends HomeController
{
	// 游戏创建列表页
	public function index()
	{
		$res = GameModel::select();
		$cate = Db::table('xt_gamelist_cate')->select();
		$this->assign(['res'=>$res,'cate'=>$cate]);
		return $this->fetch('index');
	}

	
	// 二维码生成
	public function qrcode($url)
    {
        $qrCode = new QrCode($url);
		$qrCode->setSize(146);
		// 设置高级选项 Set advanced options
		$qrCode->setWriterByName('png');
		$qrCode->setMargin(0);
		$qrCode->setEncoding('UTF-8');
		$qrCode->setErrorCorrectionLevel(ErrorCorrectionLevel::HIGH);
		$qrCode->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0, 'a' => 0]);
		$qrCode->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255, 'a' => 0]);
		$qrCode->setLogoWidth(150);
		$qrCode->setValidateResult(false);
		// 直接输出二维码 Directly output the QR code
		header('Content-Type: '.$qrCode->getContentType());
		echo $qrCode->writeString();
		exit;
	}

}